package com.yztc.wl.zhibo;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;

import android.widget.RadioGroup;

import com.yztc.wl.zhibo.totalfragment.FourFragment;
import com.yztc.wl.zhibo.totalfragment.HomeFragment;
import com.yztc.wl.zhibo.totalfragment.OneFragment;
import com.yztc.wl.zhibo.totalfragment.ThreeFragment;
import com.yztc.wl.zhibo.totalfragment.TwoFragment;

public class MainActivity extends AppCompatActivity {
    private RadioGroup radioGroup;
    FragmentManager fragmentManager;
    FragmentTransaction transaction;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        fragmentManager = getSupportFragmentManager();
        transaction = fragmentManager.beginTransaction();
        transaction.add(R.id.fragmentlayout, new HomeFragment());
        transaction.commit();
        radioGroup = (RadioGroup) findViewById(R.id.radiogroup);
        radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                 transaction = fragmentManager.beginTransaction();
                switch (checkedId) {
                    case R.id.radio_one:
                        transaction.replace(R.id.fragmentlayout, new OneFragment());
                        break;
                    case R.id.radio_two:
                        transaction.replace(R.id.fragmentlayout, new TwoFragment());
                        break;
                    case R.id.radio_home:
                        transaction.replace(R.id.fragmentlayout, new HomeFragment());
                        break;
                    case R.id.radio_three:
                        transaction.replace(R.id.fragmentlayout, new ThreeFragment());
                        break;
                    case R.id.radio_four:
                        transaction.replace(R.id.fragmentlayout, new FourFragment());
                        break;
                }
                transaction.commit();
            }

        });
    }





}

